<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.picker.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.poppicker.css" />
		<link href="../../css/mui.min.css" rel="stylesheet" />
		<!--<link rel="stylesheet" href="../../css/allApp.css" />-->
		<link rel="stylesheet" href="css/css.css" />
		<style type="text/css">
			.mui-bar .mui-title {
				right: 80px;
				left: 80px;
			}
			
			.fj-row em {
				font-style: normal;
			}
			
			.fj-row em.blue {
				color: #167ECD;
			}
			
			.fj-row a.red {
				color: #FF0000;
			}
			#sync{
				font-size: 1rem;
			}
			.jdbtns{
				padding: 3px 6px;
				border-radius: 3px;
				font-size: 14px;
				border: 1px solid #AAAAAA;
			}
			.name_line{
				width: 100%;
				padding-bottom: 7px;
				border-bottom: 1px solid #EEEEEE;
			}
			.list_name{
				display: flex;
				justify-content: space-between;
				margin-top: 7px;
			}
			.footer1 {
			    width: 100%;
			    height: 150px;
			    background-size: 100%;
			    bottom: 0;
			    position: fixed;
				display: none;
			}
			.fj-row{
				padding: 8px 20px;
			}
			.fj-btn{
				width: 100%;
				display: flex;
				justify-content: space-between;
			}
			.badegzdy{
				top: -7px;
				right: -10px;
				position: absolute;
				background-color: #0062CC;
				color: #ffffff;
				font-size: 9px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<a class="mui-pull-right" style="color: #ffffff;" id="sync">同步数据</a>
			<h1 class="mui-title">现场巡检</h1>
		</header>
		<div class="mui-content" id="content" style="margin-top:0px;display: none;">
			<div class="fj-content"style="padding-bottom: 155px;margin-top: 0px;">
				<div class="mui-row fj-row" style="padding: 13px 20px;">
					<span class="mui-pull-left">姓名:{{data.name}}</span>
					<div class="mui-pull-right">
						<div id="replaceicon">
							<span id="replace">所在场站:{{data.wname}} </span><span>></span>
						</div>
					</div>
				</div>
				<div class="mui-row fj-row" style="margin: 3px 0px;">
				 	<div class="fj-btn">
				 		<span class="jdbtns" style="position: relative;" data-type="dxj" data-url="new/dxjlistnew.html">
							待巡检<span class="mui-badge badegzdy">{{xunjian}}</span>
						</span>
				 		<span class="jdbtns" style="position: relative;"  data-type="yxj" data-url="new/yxjlist.html">
							已巡检<!-- <span class="mui-badge badegzdy">6</span> -->
						</span>
				 		<span class="jdbtns" style="position: relative;"  data-type="dsh" data-url="new/dshlist.html">
							待审核<span class="mui-badge badegzdy">{{review}}</span>
						</span>
				 		<span class="jdbtns" data-type="cgx" data-url="new/offline/dxjlist.html">草稿箱</span>
				 	</div>
				</div> 
				<div class="mui-row fj-row" style="margin-bottom: 3px;"  v-for="count in counts"  v-show="iswifi">
					<div class="name_line">
						{{changeState(count.rate)}}
					</div>
					<div class="list_name">
						<div>
							<span>巡检率</span><br/>
							<span><em class="blue">{{changepercent(count.count,count.sum)}}</em></span>
						</div>
						<div style="text-align: center;"  :data-id="(count.skipcount)" :data-type="(count.rate)">
							<span>跳检次数</span><br/>
							<span><em class="blue">{{count.skipcount}}</em></span>
						</div>
						<div style="text-align: right;" :id="(count.rate)">
							<span>未巡检次数</span><br/>
							<span><a class="red">{{count.notcount}}</a></span>
						</div>
					</div>
				</div>
				
				<div class="mui-row fj-row" v-show="iswifi">
					<div class="list_name">
						<div>
							<span>缺陷已关闭</span><br/>
							<span>{{stiobj.closeCount}}</span>
						</div>
						<div style="text-align: right;width: 200px;" class="mui-pull-left qxwgb" :data-id="(stiobj.notCloseCount)">
							<span>缺陷未关闭</span><br/>
							<span><font style="color: red;">{{stiobj.notCloseCount}}</font></span>
						</div>
					</div>
				</div>
				<div style="width: 100%;text-align: center;margin-top: 20px;font-weight: bold;font-size: 13px;">
					备注：统计数据每20分钟更新一次
				</div>
			</div>
		</div>
		
		<div id="topPopover" class="mui-popover mui-popover-add">
			<div class="sp-title">
				输入编号
			</div>
			<div class="sp-group">
				<input type="text" name="usernames" id="bianhao" placeholder="请输入编号" />
			</div>
			<div class="sp-submit">
				<div class="sp-submit-quit">
					取消
				</div>
				<div class="sp-submit-sure">
					确定
				</div>
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../js/mkeyplus.base.xunjian.js"></script>
		<script src="../../js/mui.picker.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.poppicker.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/mui.dtpicker.js"></script>
		<script type="text/javascript" src="../../js/vue.js"></script>
		<script type="text/javascript" src="./js/websql.js"></script>
		<script type="text/javascript" src="../../js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript">
			mui.init()
			
			window.vm = new Vue({
				el: "#content",
				data: {
					data: {},
					review:0,
					xunjian:0,
					counts: [{
						count:0,
						sum:0,
						skipcount:0,
						rate:0,
						notcount:0
					},{
						count:0,
						sum:0,
						skipcount:0,
						rate:1,
						notcount:0
					},{
						count:0,
						sum:0,
						skipcount:0,
						rate:2,
						notcount:0
					},{
						count:0,
						sum:0,
						skipcount:0,
						rate:3,
						notcount:0
					},{
						count:0,
						sum:0,
						skipcount:0,
						rate:4,
						notcount:0
					}],
					stiobj:{
						notCloseCount:0,
						closeCount:0
					},
					iswifi:true
				},
				methods: {
					changeState: function(cs) {
						return cs == 0 ? '天巡检' : cs == 1 ? '周巡检' : cs == 2 ? '月巡检' : cs == 3 ? '季巡检' : '半年巡检'
					},
					changepercent: function(cs, cx) {
						return cx == 0 ? '0.0%' : ((cs / cx) * 100).toFixed(1) + "%";
					},
					changeClass: function(cs) {
						return cs == '0' ? '' : 'weixunjian'
					}
				}
			
			});
			mui.plusReady(function() {
				// plus.storage.removeItem('pcchild');
				// plus.storage.removeItem('xlchild');
				// plus.storage.removeItem('xl');
				// plus.storage.removeItem('sb');
				// plus.storage.removeItem('pc');
				plus.storage.removeItem('offline');
				
				var save = JSON.parse(localStorage.getItem("savexcxj"))
				console.log('本地存储数据***' + JSON.stringify(save));
				
				data();
				getXjCount();
				function data() {
					$('#content').css('display','block');
					if (plus.networkinfo.getCurrentType()  ==  plus.networkinfo.CONNECTION_NONE)  {
						vm.iswifi = false;
						document.getElementById('sync').style.display = 'none';
						
						var personal = JSON.parse(localStorage.getItem("personal"));
						console.log('personal***' + JSON.stringify(personal));
						vm.data = personal;
						console.log('无网状态下登陆信息' + JSON.stringify(vm.data));

					} else {
						console.log('无网状态下登陆信息' +  localStorage.getItem('uname'));
						mui.baseApp.httpRequst('/api/v2/sbxj/findUserInfo', {
								username: localStorage.getItem('uname')
							},
							function(res) {
								console.log("用户信息" + JSON.stringify(res));
								var data = res.data;
								if(res.status == 200) {
									localStorage.setItem('personal', JSON.stringify(data))
									console.log('personal***' + localStorage.getItem("personal"));
									vm.data = data;
									console.log(JSON.stringify(vm.data));
								} else if(res.status == 409) {
									mui.toast(data.message)
								}
							}
						);
						var org_code = localStorage.getItem('org_code'); //获取缓存中的风场编号
						var org_code1 = JSON.parse(org_code);
						console.log(org_code1);
						mui.baseApp.httpRequst('/api/v2/sbxj/xjHomeStatistics', {
								wind: org_code1
							},
							function(res) {
								console.log("未巡检次数" + JSON.stringify(res));
								var data = res.data;
								if(res.status == 200 && data.length > 0) {
									vm.counts = data;
									console.log('++++' + JSON.stringify(vm.counts));
								} else if(res.status == 409) {
									mui.toast(data.message)
								}
							}
						);
						
						mui.baseApp.httpRequst('/api/v2/sbxj/findDefectStatistics', {
								wind: org_code1
							},
							function(res) {
								console.log("新接口" + JSON.stringify(res));
								var data = res.data;
								if(data){
									vm.stiobj = data;
								}
							}
						);
					}
				}

				clickTjcs();
				clickBtns();
				window.addEventListener('home',function(event){
					console.log('.........refresh home..........');
					data();	 
				});
				document.querySelector('.qxwgb').addEventListener('tap',function () {
				     var count = $(this).attr('data-id');
					 if(count == 0){
					 	return;
					 }
				    mui.openWindow({
				    	url: 'qxnotcloseList.html',
				    	id: 'qxnotcloseList.html',
				    	extras: {
				    	},
				    	createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
				    				
				    })
				})
			})
			
			window.addEventListener('refresh', function(e) { //执行刷新
				getXjCount()
			});
			var replacedata = "";
			var Id = "";
			var Text = "";
			
			//更换电站
			document.getElementById('replaceicon').addEventListener('tap', function() {
				pickdata();
			});
			
			function getXjCount(){
				var org_code = localStorage.getItem('org_code');
				mui.baseApp.httpRequst('/api/v2/sbxj/findXjCount', {
						memberId: localStorage.getItem('userid'),
						wind:JSON.parse(org_code)
					},
					function(res) {
						console.log('.....',JSON.stringify(res.data));
						vm.xunjian = res.data.xunjian;
						vm.review = res.data.review;
					}
				);
			}
	
			function pickdata() {
				plus.nativeUI.showWaiting();
				mui.baseApp.httpRequst('/api/v2/users/windList', {
						userid: localStorage.getItem('userid')
					},
					function(res) {
						plus.nativeUI.closeWaiting();
						var data = res.data;
						if(res.status == 200) {
							console.log("电场" + JSON.stringify(data))
							replacedata = data;
							pick(replacedata);
						} else if(res.status == 500) {
							mui.toast(data.message)
						}
					}
				);
			}
	
			function pick(replacedata) {
				var gzzjArr1 = [];
				var picker = new mui.PopPicker();
				$.each(replacedata, function(i, v) {
					gzzjObj1 = {
						value: v.id,
						text: v.name,
						org_code: v.org_code
					}
					gzzjArr1.push(gzzjObj1);
				});
				console.log("+++++"+JSON.stringify(gzzjArr1))
				picker.setData(gzzjArr1);
				$.each(gzzjArr1, function(i, v) {			
					if(JSON.parse(localStorage.getItem('windName')) == v.text) {
						picker.pickers[0].setSelectedIndex(i);					
					} 
				});
				picker.show(function(selectItems) {
					console.log('selectItems===' + JSON.stringify(picker.getSelectedItems(selectItems)))
					//localStorage.setItem("org_code",picker.getSelectedItems(selectItems)[0].org_code);
					Text=picker.getSelectedItems(selectItems)[0].text;
					Id = picker.getSelectedItems(selectItems)[0].value;
					console.log("Id" + Id);
					document.getElementById('replace').innerHTML = '所在场站:' + Text;
					
					localStorage.setItem('org_code',picker.getSelectedItems(selectItems)[0].org_code)
					getSucess(Id);
				});
			}
	
			function getSucess(Id) {
				
				plus.nativeUI.showWaiting();
				mui.baseApp.httpRequst('/api/v2/users/updateUserWind', {
						username: localStorage.getItem('uname'),
						orgid: Id
					},
					function(data) {
						console.log('data..........',JSON.stringify(data));
						if(data.status == 200) {
							getorg();
							mui.toast(data.message);
						} else if(data.status == 400) {
							plus.nativeUI.closeWaiting();
							mui.toast(data.message);
						} else if(data.status == 500) {
							plus.nativeUI.closeWaiting();
							mui.toast(data.message);
						}
					},
					function(){
						plus.nativeUI.closeWaiting();
					}
				);
							
			}
			
			//获取风场信息
			function getorg() {
				console.log("userid====="+localStorage.getItem('userid'));
				mui.baseApp.httpRequst("/api/v2/users/findUserOrg", {userid: localStorage.getItem('userid')}, 
				function(data) {
					plus.nativeUI.closeWaiting();
					console.log("获取风场信息成功" + JSON.stringify(data));
					if(data.status == 200) {
						console.log("获取风场信息成功");
						localStorage.setItem("orglist",JSON.stringify(data.data));
						localStorage.setItem("org_code",JSON.stringify(data.data[0].org_code));
						localStorage.setItem("windName",JSON.stringify(data.data[0].desc));
						console.log('org_code++++'+localStorage.getItem('org_code'));
						time(); 
						dataRe();
					}else if(data.status == "500") {
						console.log("获取风场信息失败");
					}
				}, function() {
					console.log("获取风机失败");
				})
			}
			
			function dataRe(){
				var org_code = localStorage.getItem('org_code'); //获取缓存中的风场编号
				var org_code1 = JSON.parse(org_code);
				console.log(org_code1);
				mui.baseApp.httpRequst('/api/v2/sbxj/xjHomeStatistics', {
						wind: org_code1
					},
					function(res) {
						console.log("未巡检次数" + JSON.stringify(res));
						var data = res.data;
						if(res.status == 200 && data.length > 0) {
							vm.counts = data;
							console.log('++++' + JSON.stringify(vm.counts));
						} else if(res.status == 409) {
							mui.toast(data.message)
						}
					}
				);
				
				mui.baseApp.httpRequst('/api/v2/sbxj/findDefectStatistics', {
						wind: org_code1
					},
					function(res) {
						console.log("新接口" + JSON.stringify(res));
						var data = res.data;
						vm.stiobj = data;
						
					}
				);
			}
					
					
			document.querySelector('#sync').addEventListener('tap', function() {
				//				insterData();
				if (plus.networkinfo.getCurrentType()  ==  plus.networkinfo.CONNECTION_NONE)  {
					mui.toast('无网络，无法同步数据')
				} else { 
					var btnArray = ['确认', '取消'];
					mui.confirm('确认同步数据吗？', '', btnArray, function(e) {
						if(e.index == 0) {
							time(1);
							//							websqladddata();
						} else {

						}
					})
				}
			})
			//			有网状态下存入数据库
			time(); 
			console.log("新建数据库");
			//			websqlOpenDB(); 
			             
			/*websqlCreatTable(sbInfoTable);     
			websqlCreatTable_(jcxInfoTable);*/
			/*websqlDeleteAllDataFromTable(sbInfoTable)
			websqlDeleteAllDataFromTable(jcxInfoTable) */

			/*var dataBase = websqlOpenDB();
			dataBase.transaction(function(tx) {
				tx.executeSql('drop  table  jcxInfoTable');
			});*/
			/*var dataBase = websqlOpenDB();
			dataBase.transaction(function(tx) {
				tx.executeSql('drop  table  sbInfoTable');
				alert('sbInfoTable');
			});*/

//			websqlGetAllData(jcxInfoTable);
			function clickBtns(){
				$('#content').on('tap', '.jdbtns', function() {
					var type = $(this).attr('data-type');
					var url = $(this).attr('data-url');
					if(~['dxj', 'yxj', 'dsh'].indexOf(type)){
						if (plus.networkinfo.getCurrentType()  ==  plus.networkinfo.CONNECTION_NONE)  {
							mui.toast('当前无网络！');
							return;
						}
					}
					mui.openWindow({
						url: url,
						id: url,
						extras: {},
						createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
				
					})
				});
			}
			function clickTjcs(){
				$('#content').on('tap', '.tjcs', function() {
					var count = $(this).attr('data-id');
					var rate = $(this).attr('data-type');
					console.log(count+'......'+rate);
					if(count == 0){
						return;
					}
					mui.openWindow({
						url: 'tiaojianList.html',
						id: 'tiaojianList.html',
						extras: {
							rate: rate
						},
						createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
				
					})
				
				});
			}
		</script>
	</body>

</html>